package com.logictech.lims.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.Pagenation;

import com.logictech.lims.service.LogService;
import com.logictech.lims.service.PreparationTypeService;
import com.logictech.lims.entity.PreparationType;
import com.logictech.lims.dao.PreparationTypeDao;
import com.logictech.lims.dto.PreparationTypeDto;

@Service("preparationTypeService")
public class PreparationTypeServiceImpl implements PreparationTypeService {
	@Resource
	private PreparationTypeDao preparationTypeDao;
	
	@Resource
	private LogService logService;

	@Override
	public List<PreparationTypeDto> queryList(PageQuery<PreparationTypeDto> pageQuery) {
		return preparationTypeDao.queryList(pageQuery);
	}

	@Override
	public void doAdd(PreparationType preparationType) {
		preparationTypeDao.add(preparationType);
		logService.doAdd("1",preparationTypeDao.get(preparationType.getId()));
	}

	@Override
	public void doEdit(PreparationType preparationType) {
		preparationTypeDao.update(preparationType);
		logService.doAdd("2",preparationTypeDao.get(preparationType.getId()));
	}

	@Override
	public void doDelete(String id) {
		PreparationType preparationType = preparationTypeDao.get(id);
		logService.doAdd("3",preparationType);
		preparationType.setDeleteFlag("1");
		preparationTypeDao.update(preparationType);
	}

	@Override
	public PreparationType queryById(String id) {
		PreparationType preparationType  = preparationTypeDao.get(id);
		return preparationType;
	}

	@Override
	public PageList<PreparationTypeDto> queryPageList(
		PageQuery<PreparationTypeDto> pageQuery) {
		PageList<PreparationTypeDto> result = new PageList<PreparationTypeDto>();
		Integer itemCount = preparationTypeDao.count(pageQuery);
		List<PreparationTypeDto> list = preparationTypeDao.queryPageList(pageQuery,itemCount);
		Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
		result.setPagenation(pagenation);
		result.setValues(list);
		return result;
	}
	
	@Override
	public List<PreparationTypeDto> queryAll(String name) {
		return preparationTypeDao.queryAll(name);
	}
	
}
